﻿<UserControl x:Class="XamlaApp.Views.ElementViews.TextBlockView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="Normal"/>
                <VisualState x:Name="EditMode">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="tbXamlaTextBlockView" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="tbXamlaTextBlockEdit" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.Visibility)">
                        	<DiscreteObjectKeyFrame KeyTime="00:00:00">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Selected">
                	<Storyboard>
                		<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.Visibility)">
                			<DiscreteObjectKeyFrame KeyTime="00:00:00">
                				<DiscreteObjectKeyFrame.Value>
                					<Visibility>Visible</Visibility>
                				</DiscreteObjectKeyFrame.Value>
                			</DiscreteObjectKeyFrame>
                		</ObjectAnimationUsingKeyFrames>
                	</Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Button  CacheMode="BitmapCache" Style="{StaticResource xamla_element_editbutton}" x:Name="button" Click="button_Click" Visibility="Collapsed"></Button>
        <TextBlock  CacheMode="BitmapCache"
            x:Name="tbXamlaTextBlockView"
            Text="{Binding Text}" 
            FontSize="{Binding FontSize}" 
            TextWrapping="{Binding Wrap}" 
            TextAlignment="{Binding Alignment}"
            Width="{Binding Width}"
            Height="{Binding Height}"
            Foreground="{Binding ForegroundBrush}"
            Tag="{Binding Name}"
            Opacity="{Binding Opacity}">
            <TextBlock.Projection>
                <PlaneProjection x:Name="projTest"></PlaneProjection>
            </TextBlock.Projection>            
        </TextBlock>
        <!-- The TextBox below is the editing component and becomes visible when the user enters edit mode. -->
        <TextBox 
            x:Name="tbXamlaTextBlockEdit" 
            TextChanged="tbXamlaTextBlockEdit_TextChanged"
            LostFocus="tbXamlaTextBlockEdit_LostFocus"
            GotFocus="tbXamlaTextBlockEdit_GotFocus"
            AcceptsReturn="True"
            Width="{Binding Width}" 
			Height="{Binding Height}" 
			Text="{Binding Text, Mode=OneWay}" 
			TextWrapping="{Binding Wrap}"
			FontSize="{Binding FontSize}"         
			TextAlignment="{Binding Alignment}"
            Foreground="Black"
			Tag="{Binding Name}" 
            Opacity="1" 
            Visibility="Collapsed"
			/>
    </Grid>

</UserControl>
